package com.itheima.mapper;

import com.itheima.pojo.Member;
import com.itheima.pojo.Order;
import com.itheima.pojo.OrderSetting;
import org.apache.ibatis.annotations.*;

import java.util.Date;

@Mapper
public interface OrderMapper {

    /**
     * 根据id查询预约信息
     * @param id
     */
    @Select("select * from t_order where id = #{id}")
    Order findById(Integer id);

    /**
     * 根据身份证号查询会员信息
     * @param idCard
     */
    @Select("select * from t_member where idCard = #{idCard}")
    Member findMemberByIdCard(String idCard);

    /**
     * 添加会员信息
     * @param member
     */
    @Insert("insert into t_member(idCard,name,sex,phoneNumber) values(#{idCard},#{name},#{sex},#{phoneNumber})")
    void addMember(Member member);

    /**
     * 添加预约信息
     * @param orderDate
     * @param MemberId
     * @param setmealId
     */
    @Insert("insert into t_order(orderDate,setmeal_id,member_id) values(#{orderDate},#{setmealId},#{MemberId})")
    void submitOrder(Date orderDate,Integer MemberId,Integer setmealId);

    /**
     * 根据预约日期查询预约信息
     * @param orderDate
     */
    @Select("select * from t_ordersetting where orderDate = #{orderDate}")
    OrderSetting findByOrderDate(Date orderDate);

    /**
     * 根据预约日期查询预约信息
     * @param idCard
     * @param orderDate
     * @param setmealId
     */
    @Select("select * from t_order where (select id from t_member where idCard=#{idCard})=#{idCard} and orderDate = #{orderDate} and setmeal_id=#{setmealId}")
    Order findOrderByOrderDate(@Param("idCard") String idCard,
                               @Param("orderDate") Date orderDate,
                               @Param("setmealId") Integer setmealId
    );

    /**
     * 修改预约信息
     * @param orderSetting
     */
    @Update("update t_ordersetting set reservations = #{reservations} where orderDate = #{orderDate}")
    void editNumberByOrderDate(OrderSetting orderSetting);
}
